package com.telit.firecommand.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.telit.common.entity.DataReturn;
import com.telit.firecommand.entity.CommFireOnemap;
import com.telit.firecommand.service.ICommFireOnemapService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 火点对应一张图数据 前端控制器
 * </p>
 *
 * @author yummy
 * @since 2022-04-18
 */
@RestController
@RequestMapping("/comm-fire-onemap")
@Api(tags = "火点对应一张图数据",description = "/comm-fire-onemap")
public class CommFireOnemapController {

    private Logger log = LoggerFactory.getLogger(getClass());

    @Resource
    private ICommFireOnemapService commFireOnemapService;

    @PostMapping("/add")
    @ApiOperation("添加")
    public DataReturn add(@RequestBody CommFireOnemap commFireOnemap){
        long value= commFireOnemapService.add(commFireOnemap);
        return DataReturn.ok(value);
    }

    @GetMapping("/delete/{id}")
    @ApiImplicitParam(name = "id",value = "配置ID",paramType = "path",dataType = "Integer")
    public DataReturn delete(@PathVariable("id") Long id){
        commFireOnemapService.delete(id);
        return DataReturn.ok();
    }

    @GetMapping("/deleteBatch")
    @ApiImplicitParam(name = "ids",value = "配置ID数组",paramType = "query",dataType = "integer[]")
    public DataReturn deleteBatch(Long[] ids){
        commFireOnemapService.deleteBatch(ids);
        return DataReturn.ok();
    }

    @PostMapping("/update")
    @ApiOperation("修改")
    public DataReturn update(@RequestBody CommFireOnemap commFireOnemap){
        commFireOnemapService.updateData(commFireOnemap);
        return DataReturn.ok();
    }

    @PostMapping("/search")
    @ApiOperation("条件查询+分页")
    @ApiImplicitParams({@ApiImplicitParam(name="page",value="当前页面",dataType = "int",paramType = "query"),
    @ApiImplicitParam(name="rows",value = "每页记录数",dataType = "int",paramType = "query")})
    public DataReturn findListByPage(@RequestBody(required = false) CommFireOnemap commFireOnemap, Integer page,
                                     Integer pageCount){
        IPage<CommFireOnemap> commFireOnemapPage = commFireOnemapService.findListByPage(commFireOnemap,page, pageCount);
        Map<String,Object> retMap=new HashMap<String,Object>();
        retMap.put("commFireOnemap",commFireOnemapPage.getRecords());
        retMap.put("total",commFireOnemapPage.getTotal());
        return DataReturn.ok(retMap);
    }

    @PostMapping("/searchNoPage")
    @ApiOperation("条件查询")
    public DataReturn searchNoPage(@RequestBody(required = false) CommFireOnemap commFireOnemap){
        List<CommFireOnemap> commFireOnemapList = commFireOnemapService.searchNoPage(commFireOnemap);
        return DataReturn.ok(commFireOnemapList);
    }

    @GetMapping("/findOne/{id}")
    @ApiOperation("根据id获取配置实体")
    @ApiImplicitParam(name = "id",value = "配置ID",paramType = "path",dataType = "Long")
    public DataReturn findById(@PathVariable Long id){
        CommFireOnemap commFireOnemap= commFireOnemapService.findById(id);
        return DataReturn.ok(commFireOnemap);
    }
}
